<template>
  <div>
    <!-- 分界线-->
    <el-divider>
      <span style=" font-size: 25px; font-weight: bold;"></span>
    </el-divider>
    <!-- 表单部分 -->
    <!-- 订单介绍表格-->
    <el-table :data="tableData" v-loading="loading" style="width: 100%">
      <el-table-column header-align="center" align="center" label="图片">
        <template slot-scope="scope">
          <el-image :src="scope.row.imgUrl" style="width: 100px; height: 100px"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="攻略信息" width="520">
        <template slot-scope="scope">
          <el-row style="margin-bottom: 10px;">
            <el-image :src="scope.row.icon" style=" width: 50px;
                height: 50px;
                border-radius: 100px;"></el-image>
            <span style="font-size: 23px; font-weight: bold; color:dodgerblue;">
              {{ scope.row.userName }}</span>
          </el-row>
          <span style="font-size: 23px; font-weight: bold; color:dodgerblue;">
            {{ scope.row.title }}</span><br />
          <span>
            <img style=" width: 25px;vertical-align: middle;
              height: 25px;" src="../../assets/images/sc.png" />
            {{ scope.row.collects }}</span>
          <span> </span>
          <span style="margin: 0 10px;">
            <img style=" width: 25px; vertical-align: middle;
              height: 25px;" src="../../assets/images/dz.png" />

            {{ scope.row.liked }}</span><br />
          <span>{{ scope.row.addTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="orderDetail(scope.row.id)">查看详情</el-button>
          <el-button size="mini" type="primary" @click="updateBy(scope.row.id)">修改</el-button>
          <el-button size="mini" type="danger" @click="deleteBy(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNum"
      :page-sizes="[5, 10, 20, 30]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import newAxios from "../../utils/axios";
export default {
  name: "hotel",
  data() {
    return {
      tableData: [],
      pageSize: 5,
      pageNum: 1,
      total: 0,
      filter: {},
      loading: false,
      icon: "",
    };
  },
  created() {
    //获取攻略列表数据
    this.loadStrategy();
    this.getUser();
  },
  methods: {
    updateBy() { },

    //删除攻略
    deleteBy(id) {
      this.$confirm("此操作将永久删除该攻略, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          newAxios
            .post("/strategy/deleteByUser", {
              productId: id,
              productType: 5,
            })
            .then((res) => res.data)
            .then((res) => {
              console.log(id);
              console.log(res);
              if (res.code == 200) {
                this.loadStrategy();
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });
              } else {
                this.$message.error("删除失败！");
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    //攻略详情页跳转的方法
    orderDetail(id) {
      console.log("id:" + id);
      this.$router.push({
        path: "/StrategyDetail",
        query: {
          strategyId: id,
        },
      });
    },

    //修改攻略跳转的方法
    updateBy(id) {
      console.log("id:" + id);
      this.$router.push({
        path: "/updateStrategy",
        query: {
          strategyId: id,
        },
      });
    },

    //获取攻略的数据列表以及分页信息
    loadStrategy() {
      newAxios
        .post("/strategy/listMyStrategy", {
          currentPage: this.pageNum,
          pageSize: this.pageSize,
          title: this.filter.title,
          state: 1,
        })
        .then((res) => {
          if (res.data.code == 200) {
            this.tableData = res.data.data;
            this.total = res.data.total;
          }
        });
    },
    getUser() {
      newAxios
        .get("/admin/findUserById")
        .then((res) => res.data)
        .then((res) => {
          if (res.code == 200) {
            console.log(res.data);
            this.myInfo = res.data;
          } else {
            this.$message.error("请先登录噢亲！！");
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //条件分页查询
    filterquery() {
      this.loadStrategy();
    },

    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageNum = 1;
      this.pageSize = val;
      this.loadStrategy();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNum = val;
      this.loadStrategy();
    },
  },
};
</script>

<style>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
